﻿package shooter 
{
	import com.greensock.TweenNano;
	import flash.display.BitmapData;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.geom.ColorTransform;
	import flash.geom.Matrix3D;
	import render3d.CrossEngineObject3D;
	import render3d.interfaces.IRender3DAdapter;
	import render3d.interfaces.IRender3DForObject3D;

	public class Monster extends CrossEngineObject3D
	{	
		[Embed(source='../../assets/field_rat.png')] static private const FIELD_RAT_CLASS:Class;
		static public const FIELD_RAT_BITMAP_DATA:BitmapData = new FIELD_RAT_CLASS().bitmapData;
		
		[Embed(source='../../assets/field_rat_killed.png')] static private const FIELD_RAT_KILLED_CLASS:Class;
		static public const FIELD_RAT_KILLED_BITMAP_DATA:BitmapData = new FIELD_RAT_KILLED_CLASS().bitmapData;
		
		static private const KILLED_COLOR_TRANSFORM:ColorTransform = new ColorTransform(1, 1, 1, 1, 25, 0, -25, 0)
		static private const DESTROY_DELAY:Number = 0.2; //seconds
		
		public var width:int;
		public var height:int;
		public var isAlive:Boolean = true;
		public var boundingRadius:Number;
		
		public function Monster(render:IRender3DAdapter, name:String ) 
		{
			super(IRender3DForObject3D(render))
			this.width = FIELD_RAT_BITMAP_DATA.width;
			this.height = FIELD_RAT_BITMAP_DATA.height;
			boundingRadius = Math.max(FIELD_RAT_BITMAP_DATA.width, FIELD_RAT_BITMAP_DATA.height) * 3;
			//this.originScale = this.scaleX = this.scaleY = this.scaleZ = 0.45;
			//this.originScale = 0.45;
			//this.matrix.appendScale(originScale, originScale, originScale);
			_object3D = render.createSprite3D(FIELD_RAT_BITMAP_DATA, "monster").object3D;	
		}
		
		public function animateOut():void 
		{
			this.changeTexture(FIELD_RAT_KILLED_BITMAP_DATA);
			TweenNano.delayedCall(DESTROY_DELAY, destroy);
		}

		public function destroy():void 
		{
			isAlive = false;
			render.removeChild(this);
		}
	}	
}